package car;

import java.awt.*;


public class CirclePanel {

    private static final int DEFAULT_POINTER_LENGTH_RATIO = 50;
    private static final int DEFAULT_STROKE_WIDTH = 2;

     public static void drawCirclePanel(Graphics2D g2, int x, int y, int width, int height, int max, int value, int startAngle, int arcAngle, int step, String format) {
        g2.setColor(Color.BLACK);
        g2.drawArc(x, y, width, height, startAngle, arcAngle);

        for (int i = 0; i <= max; i += step) {
            double angle = Math.toRadians(startAngle + (i * arcAngle / (double) max));
            int x1 = x + width / 2 + (int) (width / 2 * Math.cos(angle));
            int y1 = y + height / 2 - (int) (height / 2 * Math.sin(angle));
            int x2 = x + width / 2 + (int) (width / 2.2 * Math.cos(angle));
            int y2 = y + height / 2 - (int) (height / 2.2 * Math.sin(angle));
            g2.drawLine(x1, y1, x2, y2);

            String text = String.format(format, i);
            int textX = x2 + 15;
            int textY = y2 + 5;
            TextPanel.drawTextPanel(g2, text, textX, textY);
        }

        double pointerAngle = Math.toRadians(startAngle + (value * arcAngle / (double) max));

        int pointerLength = (int) (width * DEFAULT_POINTER_LENGTH_RATIO / 100.0);

        int centerX = x + width / 2;
        int centerY = y + height / 2;

        int endX = centerX + (int) (pointerLength * Math.cos(pointerAngle));
        int endY = centerY - (int) (pointerLength * Math.sin(pointerAngle));

        g2.setColor(Color.RED);
        g2.setStroke(new BasicStroke(DEFAULT_STROKE_WIDTH));
        g2.drawLine(centerX, centerY, endX, endY);
    }
}
